<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <%
		String base = request.getContextPath();
		request.setAttribute("base", base);
	%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${base}/resources/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
	function submit(){
		var id=$("#id").val();
		var price=$("#price").html();
		var count=$("#count").val();
		$.ajax({
			url:"${base}/insertShopping",
			data:{'commodityid':id,'commodityprice':price,"commoditycount":count},
			type:'post',
			success:function(data){
			    if(data=="success"){
			    	location.href="${base}/CommodityController/show";
			    }else{
			    	alert("添加失败");
			    }
			}		
		})
	}
	
	function confirm(){
		var id=$("#id").val();
		var price=$("#price").html();
		var count=$("#count").val();
		$.ajax({
			url:"${base}/insertOrder",
			data:{'commodityid':id,'commodityprice':price,"commoditycount":count},
			type:'post',
			success:function(data){
			    if(data=="success"){
			    	alert("购买成功");
			    	location.href="${base}/CommodityController/show";
			    }
			}		
		})
	}
</script>
</head>
<body>

	<div>
		
		<div style="float: left;width: 150px;height: 150px;margin-left: 10px;margin-top: 10px;border: 1px solid blue;"><a href=""><img src="${base}/resources/images/none.jpg"></a></div>
		<div style="float: left;width: 150px;height: 150px;border: 1px solid blue;margin-left: 10px;margin-top: 10px;text-align: center;">
			<input type="hidden" value="${commodity.commodityid}" id="id">
			<h6>名字:${commodity.commodityname}<br/>价格:<span id="price">${commodity.commodityprice}</span><br/>
				数量:<input value="1" id="count" style="width: 15px;"><br/>
				<input type="button" onclick="submit()" value="加入购物车">
				<input type="button" value="确认购买" onclick="confirm()">
			</h6>
		</div>
	</div>
</body>
</html>